package com.xujian.common.beans;

import com.alibaba.fastjson2.JSON;
import com.xujian.common.util.RandomOptionGroup;
import lombok.Builder;
import lombok.Data;

import java.util.List;

/**
 * @author star xu
 * @date 2023/4/3 11:30
 * @Description:
 * @Slogan: 致敬大师,致敬未来的自己
 */
@Data
@Builder
public class AppMain {
    private Long ts;   // (String) 客户端日志产生时的时间

    private AppCommon common;

    private AppPage page;

    private AppError err;

    private AppNotice notice;

    private AppStart start;

    private List<AppDisplay> displays;
    private List<AppAction> actions;

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    public static class AppMainBuilder {

        public void checkError() {
            Integer errorRate = AppConfig.error_rate;
            Boolean ifError = RandomOptionGroup.builder().add(true, errorRate).add(false, 100 - errorRate).build().getRandBoolValue();
            if (ifError) {
                AppError appError = AppError.build();
                this.err = appError;
            }
        }
    }
}
